#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,v,cnt,light;
int car[100005];
bool crime[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
    cnt=0;light=0;n=0;m=0;l=0;v=0;
    memset(car,0,sizeof(car));
    memset(crime,0,sizeof(crime));
    cin>>n>>m>>l>>v;
    for(int i=1;i<=n;i++){
        cin>>car[i];
        int a,b;
        cin>>a;
        if(a>v){
            cnt++;
            crime[i]=1;
        }
        cin>>b;
    }
    for(int i=1;i<=m;i++){
        int c;
        cin>>c;
        if(c>light) light=c;
    }
    for(int i=1;i<=n;i++){
        if(crime[i]==1){
            if(car[i]>light) cnt--;
        }
    }
    if(cnt!=0)
        cout<<cnt<<" "<<m-1<<endl;
    else
        cout<<cnt<<" "<<m<<endl;
    }
    return 0;
}

